import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { CartVO, CartForm, CartQuery } from '@/api/shopping/product/cart/types';

/**
 * 查询购物车列表
 * @param query
 * @returns {*}
 */

export const listCart = (query?: CartQuery): AxiosPromise<CartVO[]> => {
  return request({
    url: '/shopping/cart/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询购物车详细
 * @param id
 */
export const getCart = (id: string | number): AxiosPromise<CartVO> => {
  return request({
    url: '/shopping/cart/' + id,
    method: 'get'
  });
};

/**
 * 新增购物车
 * @param data
 */
export const addCart = (data: CartForm) => {
  return request({
    url: '/shopping/cart',
    method: 'post',
    data: data
  });
};

/**
 * 修改购物车
 * @param data
 */
export const updateCart = (data: CartForm) => {
  return request({
    url: '/shopping/cart',
    method: 'put',
    data: data
  });
};

/**
 * 删除购物车
 * @param id
 */
export const delCart = (id: string | number | Array<string | number>) => {
  return request({
    url: '/shopping/cart/' + id,
    method: 'delete'
  });
};
